#ifndef IST8310_H
#define IST8310_H

#include <cstdint>
#include <array>

class I2CDevice {
public:
    virtual ~I2CDevice() = default;
    virtual bool read(uint8_t reg, uint8_t* buf, size_t len) = 0;
    virtual bool write(uint8_t reg, const uint8_t* buf, size_t len) = 0;
};

class LinuxI2C : public I2CDevice {
public:
    LinuxI2C(const char* device);
    ~LinuxI2C();

    bool read(uint8_t reg, uint8_t* buf, size_t len) override;
    bool write(uint8_t reg, const uint8_t* buf, size_t len) override;

private:
    int fd;
};

class IST8310 {
public:
    explicit IST8310(I2CDevice& device);
    
    std::array<int16_t, 3> getMagVector();
    int16_t getTemperature();

private:
    I2CDevice& device;

    bool readRegister(uint8_t reg, uint8_t* data, size_t len);
    bool writeRegister(uint8_t reg, const uint8_t* data, size_t len);
};

#endif // IST8310_H
